package day12;

import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class ListTest {
    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        ListPuter p=new ListPuter(list);
        Thread th=new Thread(p);
        Thread th1=new Thread(p);
        Thread th2=new Thread(p);
        th.start();
        th1.start();
        th2.start();
    }
}
class ListPuter implements Runnable{
    private final List<String> list;

    public ListPuter(List<String> list){
        this.list=list;
    }
    @Override
    public  void run() {
        for(int i=1;i<=1000;i++){
            if(i%100==0)
                System.out.println(Thread.currentThread().getName()+" "+i);
            synchronized(list){
                list.add(Thread.currentThread().getName()+" "+i);
            }

        }
    }
}